#include "route.h"

Route::Route()
{

}

QString Route::find(QString &route, const QString &variable)
{
    auto var = route.trimmed();
    auto index = var.indexOf(variable);
    if (index < 0) {
        return QString();
    }

    var = var.mid(index);
    auto splits = var.split(" ");
    if (splits.length() < 2) {
        return QString();
    }

    return splits.at(1);
}

void Route::parser(QString route, QString &ip, QString &via, QString &dev, QString &proto, QString &scope, QString &src, QString &metric)
{
    auto first = route.split(QRegExp("\\s")).first();
    if (first.contains(".")){
        ip = first;
    }

    via = find(route, "via");
    dev = find(route, "dev");
    proto = find(route, "proto");
    scope = find(route, "scope");
    src = find(route, "src");
    metric = find(route, "metric");
}
